//
//  VoiceAssistant.m
//  VoiceAssistant
//
//  Created by G on 2020/2/15.
//  Copyright © 2020年 G. All rights reserved.
//

#import "VoiceAssistant.h"
#import "IFlyAIUI/IFlyAIUI.h"
#import "ChatDemoController3.h"

@implementation VoiceAssistant

+ (void)defaultSetting {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *cachePath = [paths objectAtIndex:0];
    cachePath = [cachePath stringByAppendingString:@"/"];
    
    NSLog(@"cachePath=%@",cachePath);
    
    [IFlyAIUISetting setSaveDataLog:NO];
    [IFlyAIUISetting setLogLevel:LV_INFO];
    [IFlyAIUISetting setAIUIDir:cachePath];
    [IFlyAIUISetting setMscDir:cachePath];
}

+ (void)openVoiceAssistant:(NSDictionary *)options answer:(BOOL (^)(NSString * _Nonnull answer, NSDictionary *dict))onNlpAnswerText finish:(VoidBlock)onTTSFinished {
    [self defaultSetting];
    
    UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
    ChatDemoController3 *vc = [ChatDemoController3 new];
    vc.hidesBottomBarWhenPushed = YES;
    vc.modalPresentationStyle = UIModalPresentationFullScreen;
    __weak typeof(vc) weakVc = vc;
    vc.onNlpAnswerText = ^(NSString * _Nonnull answer, NSDictionary *dict) {
        //
        if (onNlpAnswerText && onNlpAnswerText(answer, dict)) {
            weakVc.onTTSFinished = onTTSFinished;
        }
    };
    
    // [rootViewController.navigationController pushViewController:vc animated:YES];
    vc.customBeingPresented = YES;
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    nav.navigationBarHidden = YES;
    //nav.modalPresentationStyle = UIModalPresentationFullScreen;
    [rootViewController presentViewController:nav animated:YES completion:nil];
}

@end
